*12345678901234567890123456789012345678901234567890123456789012345678901234567890

capture log close
clear
clear matrix
set mem 500m
set more off

#delimit ;

*log using "C:\Documents and Settings\James\Desktop\My Dropbox\Collaboration with Peter\baccini_match2.log", 
replace;

*	************************************************************************ *;
* 	File-Name: baccini_match2.do											 *;
*	Date:  11/23/09															 *;
*	Author: 	James Hollyer                                                *;
*	Purpose:   To merge the matching weights generated from the collapsed 	 *;
*	Baccini dataset in R with the full dataset and then re-run models on the *;
*	matched data.														 	 *;
*	Data Input: baccinimatched.dta, baccini_survival2.dta					 *;
*	************************************************************************ *;


*	************************************************************************ *;
*	The following will merge the weights from the matched dataset with the   *;
*	baccini_survival2.dta dataset.  										 *;
*	************************************************************************ *;

use "c:\documents and settings\james\desktop\my dropbox\PTAs\HollyerRosendorffReplicationMaterials\baccini_survival2.dta";

sort leadid year;

merge m:1 leadid using "c:\documents and settings\james\desktop\my dropbox\PTAs\HollyerRosendorffReplicationMaterials\baccinimatched2.dta";

*As should be the case, there are observations in the master file that are not;
*in the matched (pruned) dataset.  Drop these.;

drop if _merge~=3;

drop _merge;

stset endobs, id(leadid) fail(fail==1) origin(eindate) 
enter(time mdy(1,1,1995)) scale(365.25); 

*	************************************************************************ *;
*	The following will re-run the main models from the preliminary 			 *;
*	regressions.  These results are reported as Table 5 in the paper.  This  *;
*	code will also generate Figure 2 in the paper.							 *;
*	************************************************************************ *;

gen log_num_pta_sign=.;
replace log_num_pta_sign=ln(num_pta_lead_sign+1);

gen pta_sign_dem = pta_lead_sign*polity2;
gen pta_num_dem = log_num_pta_sign*polity2;

eststo: stcox  log_num_pta_sign polity2  pta_num_dem rgdpch openk grgdpch, 
tvc(log_num_pta_sign polity2 pta_num_dem) shared(ccode) nohr;


est2vec PTA_matched_nearest, replace name(Model1) vars(log_num_pta_sign pta_lead_sign polity2 pta_num_dem pta_sign_dem rgdpch openk grgdpch);



eststo: stcox  log_num_pta_sign polity2 pta_num_dem rgdpch openk grgdpch, 
shared(ccode) nohr;

estat phtest, rank detail;

sum log_num_pta_sign;

local max_log_pta=r(max);
local max_pta_min_polity=`max_log_pta'*-10;
local max_pta_max_polity=`max_log_pta'*10;

stcurve, hazard at1(polity2=-10  log_num_pta_sign=0  pta_num_dem=0) 
at2(polity2=-10 log_num_pta_sign=0.693 pta_num_dem=-6.93) 
at3(polity2=-10 log_num_pta_sign=`max_log_pta' pta_num_dem = `max_pta_min_polity')
graphregion(fcolor(white)) ytitle(Hazard Rate) xtitle(Years in Office) 
scheme(s2mono) legend(label(1 No PTA) label(2 One PTA) label(3 Max PTAs)) 
name(minpolity, replace) subtitle(Minimum Polity Score);

stcurve, hazard at1(polity2=10  log_num_pta_sign=0  pta_num_dem=0) 
at2(polity2=10 log_num_pta_sign=0.693 pta_num_dem=6.93) 
at3(polity2=10 log_num_pta_sign=`max_log_pta' pta_num_dem =`max_pta_max_polity')
graphregion(fcolor(white)) ytitle(Hazard Rate) xtitle(Years in Office) 
scheme(s2mono) legend(label(1 No PTA) label(2 One PTA) label(3 Max PTAs)) 
name(maxpolity, replace) subtitle(Maximum Polity Score);

graph combine minpolity maxpolity, ycommon graphregion(fcolor(white))
title(Estimated Hazard Rates);

*graph export "C:\Documents and Settings\James\Desktop\My Dropbox\Collaboration with Peter\matchedmfx.png",
replace;


eststo: stcox  log_num_pta_sign polity2 rgdpch openk grgdpch, 
tvc(log_num_pta_sign polity2) shared(ccode) nohr;

est2vec, addto(PTA_matched_nearest) name(Model3);

stcox pta_lead_sign polity2 pta_sign_dem rgdpch openk grgdpch, shared(ccode) nohr;

est2vec, addto(PTA_matched_nearest) name(Model2);

stcox pta_lead_sign polity2 rgdpch openk grgdpch, shared(ccode) nohr;

est2vec, addto(PTA_matched_nearest) name(Model4);

*est2tex PTA_matched_nearest, preserve path("C:\Documents and Settings\James\Desktop\My Dropbox\Collaboration with Peter\") 
mark(stars) dot replace;

 
*	************************************************************************ *;
*	The following will close the log file.									 *;
*	************************************************************************ *;

log close;
